import { AnimationClip, Canvas, Color, Component, director, instantiate,Node } from "cc";
import { aa } from "../frame/FrameCore";
import { AssetType, ChatType, Key, TaskType, aaEvent, anmClip, ui } from "../frame/common/Enums";
import chatMgr from "./ChatMgr";
import utilsMgr from "../frame/common/Utils";


export class SceneMgr extends Component{

    async loadHome(){
        aa.ui.get(ui.ToastView);

        aa.global.isGame = false;
        aa.res.resetTimer();
        await aa.res.loadBundle(2);
        await aa.res.loadRes(2, AssetType.UiPrefab);
        aa.ui.get(ui.ChatView);
 
    }
    async loadFirst(){

        await aa.res.loadBundle(1, 0.05);
        await aa.res.loadRes(1, AssetType.UiPrefab, 0.9501);  
        aa.ui.get(ui.DecoView);
    }
    createScene(){
        this.newLayers(6, aa.global.canvas[1]);
        this.newScenes(6, aa.global.main);
    }

    public newLayers(amount = 6, canvas: Canvas) {
        const layer2D = aa.global.layers;
        for (var i = 0; i <= amount; i++) {
            /* if layer0 exist, we clone it, otherwise create a new one */
            const node = layer2D[0] ? instantiate(layer2D[0]) : utilsMgr.createUI();
            node.name = "layer" + i;
            node.parent = canvas.node;
            layer2D[i] = node;
        }
    }
    public newScenes(amount = 6, parent: Node) {
        const scenes = aa.global.scenes;
        for (var i = 0; i <= amount; i++) {
            /* if layer0 exist, we clone it, otherwise create a new one */
            const node = new Node("scene" + i);
            node.parent = parent;
            scenes[i] = node;
        }
    }
    
}
const sceneMgr = new SceneMgr;

export default sceneMgr;

